class Solution:
    def getRow(self, rowIndex: int):
        # if rowIndex+1 <= 2: return [1]*(rowIndex+1)
        # dp = [[1]*i for i in range(1, rowIndex+2)]
        # rowNum = 2
        # while rowNum < rowIndex + 1:
        #     for i in range(1, len(dp[rowNum]) - 1):
        #         dp[rowNum][i] = dp[rowNum-1][i-1] + dp[rowNum-1][i]
        #     rowNum += 1
        # return dp[rowIndex]

        # 数学的方法
        # res = [1]
        # for i in range(1, rowIndex + 1):
        #     res.append(int(res[i - 1] * (rowIndex - i + 1) / i))
        # return res

        if rowIndex+1 <= 2: return [1]*(rowIndex+1)
        result = [1, 1]
        rowNum = 2
        while rowNum < rowIndex + 1:
            result.insert(0, 0)
            for i in range(rowNum):
                result[i] = result[i+1] + result[i]
            rowNum += 1
        return result
